<?php
class Settings
{
	private static $_instance = null;
	private $_db = null;
	
	private function __construct()
	{
		$this->_db = Yii::app()->db;
		$this->_db->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
	}
	
	public static function getInstance() 
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }
	
	public function getList(array $args = array())
	{
		try{
			$defaults = array();
			$args = array_merge($defaults, $args);
			
			$strSQL = " 	
						SELECT * 
						FROM tbl_settings
					  ";
			$cmd = $this->_db->createCommand($strSQL);			
			$arrResults = $cmd->queryAll();
			return $arrResults;
		} catch(Exception $ex){
			throw new Exception($ex->getMessage());
		}
	}
	
	public function update($id, $value){
		$args = array(
			'setting_value' => $value			
		);
		$cmd = $this->_db->createCommand();
		return $cmd->update('tbl_settings',$args, 'setting_code=:id', array(':id'=>$id));
	}
}